<!--修改密码-->

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	    <link rel="stylesheet" href="/static/css/backstage/amazeui.min.css" >
		<link rel="stylesheet" href="/static/css/backstage/admin.css" >
		<link rel="stylesheet" href="/static/css/backstage/app.css" >
		<style>
			.admin-main{
				padding-top: 0px;
			}
			.error{
				color:red;
			}
			.success{
				color:#5eb95e;
			}
		</style>
	</head>
	<body>
		<div class="am-cf admin-main">
		<!-- content start -->
		<div class="admin-content">
			<div class="admin-content-body">
				<div class="am-g">
					<form class="am-form am-form-horizontal"	 method="post"	style="padding-top:30px;" data-am-validator>
						<input value="${admin_name.a_id}" name="roleId" type="hidden">
						<div class="am-form-group">
							<label for="user-name" class="am-u-sm-3 am-form-label">
								原密码</label>
							<div class="am-u-sm-9">
								<input type="password" id="doc-vld-pwd-2" required placeholder="请输入原密码"
									   name="oldpwd"  data-equal-to="#doc-vld-pwd-1"  required> <small>输入原密码。</small>
							</div>
						</div>
						<div class="am-form-group">
							<label for="user-name" class="am-u-sm-3 am-form-label">
							新密码 </label>
							<div class="am-u-sm-9">
								<input type="password" id="password" required placeholder="请输入新密码"
									name="password" onBlur="checkPassword()"> <small id="passwordErr">输入新密码。</small>
							</div>
						</div>
						<div class="am-form-group">
							<label for="user-name" class="am-u-sm-3 am-form-label">
								重复密码</label>
							<div class="am-u-sm-9">
								<input type="password" id="password2" required placeholder="请输入重复密码"
									name="pwd"  data-equal-to="#doc-vld-pwd-1"  required onBlur="checkPassword2()"> <small id="passwordErr2">输入重复密码。</small>
							</div>
						</div>
						<div class="am-form-group">
							<div class="am-u-sm-9 am-u-sm-push-3">
								<input type="button" class="am-btn am-btn-success updatepwd" value="修改密码" />
								<input class="am-btn am-btn-primary" onclick="javascript:window.history.back();" value="返回上级" type="button">
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript" src="/static/js/backstage/jquery-1.8.3.js" ></script>
	<script type="text/javascript" src="/static/js/backstage/plugs.js" ></script>
	<script>
		//验证密码
		function checkPassword(){
			var userpasswd = document.getElementById('password').value;
			var reg = /^.*[~!@#\$%\^&\*\(\)_+\-=\[\]\{\}\\\|\'\";:,\<\.\>\/\?\s+].*$/;
			var regNumber = /\d+/; //验证0-9的任意数字最少出现1次。
			var regString = /[a-zA-Z]+/; //验证大小写26个字母任意字母最少出现1次。
			if(userpasswd.length == 0){
				document.getElementById('passwordErr').innerHTML="密码不能为空";
				document.getElementById('passwordErr').className="error";
				return false;
			}
			else if(userpasswd.length<4||userpasswd.length>10){
				document.getElementById('passwordErr').innerHTML="密码长度要大于4个字符并且小于10个字符";
				document.getElementById('passwordErr').className="error";
				return false;
			}
			else if(!(regNumber.test(userpasswd) && regString.test(userpasswd) || reg.test(userpasswd))){
				document.getElementById('passwordErr').className="error";
				document.getElementById('passwordErr').innerHTML="密码中要包含字符串、数字可包含特殊符号！";
				return false;
			}
			else{
				document.getElementById('passwordErr').className="success";
				document.getElementById('passwordErr').innerHTML="OK";
				return true;
			}
		}

		function checkPassword2(){
			if($("#password2").val()==$("#password").val())
			{
				document.getElementById('passwordErr2').className="success";
				document.getElementById('passwordErr2').innerHTML="OK";
				return true;
			}
			else
			{
				document.getElementById('passwordErr2').className="error";
				document.getElementById('passwordErr2').innerHTML="两次密码输入不一致";
				return false;
			}
		}

		$(".updatepwd").click(function(){
			if(checkPassword()&&checkPassword2())
			{
				$.ajax({
					url:"/backstage/doUpatePwd",
					dataType:"json",
					type:"put",
					data:$("form").serialize(),
					success:function(result){
						<!--console.log(result);-->
						alert(result.tips);
						if(result.tips=="修改成功！")
							window.parent.location.href="/backstage/backstage_logout";
					},
					error:function(result){
						alert("系统繁忙！");
					 }
				});
			}
		});
	</script>
	</body>
</html>
